<?php
if (!defined('IN_IA')) {
	die('Access Denied');
}
global $_W, $_GPC;
$id = $_GPC['gold_id'];
$openid = m('user')->getOpenid();
$member = m('member')->getInfo($openid);
$gold_log = pdo_fetch("SELECT * FROM " . tablename('ewei_shop_commission_gold_log') . " WHERE id = '{$id}' and uniacid = '{$_W['uniacid']}' and status = 0 ");
$access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx4d6a0644cae71c05&secret=e57902975056e739bae60ae12c6c1419";
$access_msg = json_decode(file_get_contents($access_token));
$token = $access_msg->access_token;
$subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$_W[openid]";
$subscribe = json_decode(file_get_contents($subscribe_msg));
$gzxx = $subscribe->subscribe;
    $userinfo= pdo_fetch("SELECT * FROM " . tablename('ewei_shop_member') . " WHERE uid = '{$member['uid']}' and uniacid = '{$_W['uniacid']}'");
    if(empty($userinfo['realname']) || empty($userinfo['mobile']) || empty($userinfo['weixin']) || empty($userinfo['province']) || empty($userinfo['city'])){
         if($gzxx === 1){
         $url="http://wx.lanxuevip.com/app/index.php?i=5&c=entry&p=info&do=member&saoma=true&m=ewei_shop&gold_id=".$_GPC['gold_id'];
         header("Location: $url");
         exit;
         }
    }
if(!empty($gold_log) && $gzxx === 1){
        if($member['id'] != $gold_log['mid']){
            //修改金币
            $info= pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE uid = '{$member['uid']}' and uniacid = '{$_W['uniacid']}'");
            if(empty($info)){
             exit;   
            }
            $gold_card = intval($info['gold_card']) + intval($gold_log['money']);
            pdo_update('mc_members', array('gold_card' => $gold_card), array('uniacid' => $_W['uniacid'], 'uid' => $member['uid']));
            $data =array(
               'openid'=>$openid,
                'gettime'=>time(),
                'status'=>1
            );
            pdo_update('ewei_shop_commission_gold_log',$data,array('uniacid' => $_W['uniacid'], 'id' => $gold_log['id']));
            $gold_ok = 1;
        }else{
            $gold_ok = 0;//小店用户自己不能领取  
        }
}else{
	$gold_ok = 0;
}
include $this->template('gold/list');

